import base from '../api/base'

const state = {
  loading: false,
  isLogin: false,
  urlETag: {}
}

const getters = {}

const actions = {
  login ({ commit }, params) {
    const { cb, ...others } = params
    base.login({
      cb: result => {
        cb && cb(result)
        commit('setIsLogin', true)
      },
      ...others
    })
  }
}

const mutations = {
  setLoading (state, loading) {
    state.loading = loading
  },
  setIsLogin (state, isLogin) {
    state.isLogin = isLogin
  },
  setUrlETag (state, urlETag) {
    state.urlETag = urlETag
  },
  setUrlETagItem (state, item) {
    const { url, ETag } = item
    state.urlETag[url] = ETag
  }
}

export default {
  namespaced: true,
  state,
  getters,
  actions,
  mutations
}
